/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Negocio;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author jorge.correa
 */
public class consulta extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        try {              
                                       
            String strConsecutivo = request.getParameter("txtConsecutivo");
            String strCedulaUser = (String) request.getParameter("txtCedula");
        
            String[] strDatos = GestionSQL.getFila("select m.dtFechaRecepcion, m.intPersona, p.strNombre, e.strNombre, m.dtFechaEntrega, m.strDescripcion from tbl_personas p, tbl_muestras m, tbl_estados e where (p.intCedula = m.intPersona) and (m.strEstado = e.strCodigo) and (m.strConsecutivo = '" + strConsecutivo +"')");
            
            if (strDatos == null){
               out.println("<html>");
               out.println("<head>");
               out.println("</head>");
               out.println("<body>");
               out.println("<div class='TEXTOFALLO'>");
               out.println("No se encontró la muestra con el número de consecutivo " + strConsecutivo +".");
               out.println("</div>");
               out.println("</body>");
               out.println("</html>");
            }else{
               String strFechaRecep = (String)strDatos[0];
               String strCedula = (String) strDatos[1];
               String strNombre = strDatos[2];
               String strEstado = strDatos[3];
               String strFechaEntrega = (String)strDatos[4];
               String strDescripcion = strDatos[5];                    
      
               if (strCedulaUser.equals(strCedula)){
                   out.println("<html>");
                   out.println("<head>");
                   out.println("</head>");
                   out.println("<body>");              
                   out.println("<table cellspacing='0' cellpadding='0' width='1080px' border='0'>");
                   out.println("<tr>");
                   out.println("<td class='TITULOFORM'>RESULTADO DE LA CONSULTA</td>");
                   out.println("</tr>");
                   out.println("<tr>");
                   out.println("<td>");
                   out.println("<form method='POST' action='#' id='frmResult' name='frmResult'>");
                   out.println("<table cellspacing='0' cellpadding='5' width='1080px' border='0' class='TABLAHEAD' style='background: #FFC;'>");
                   out.println("<tr>");
                   out.println("<td colspan='4'></td>");             
                   out.println("</tr>");
                   out.println("<tr>");
                   out.println("<td class='LABELRESULT'>Consecutivo:</td>");
                   out.println("<td class='CELDACAMPORESULT'><input type='text' name='txtConsecutivo' value='" + strConsecutivo + "' id='txtConsecutivo' class='CAMPORESULT' readonly='read-only'></td>");
                   out.println("<td class='LABELRESULT'>Fecha de recepción:<br>(aaaa-mm-dd)</td>");
                   out.println("<td class='CELDACAMPORESULT'><input type='text' name='txtFechaRecep' value='" + strFechaRecep + "' id='txtFechaRecep' class='CAMPORESULT' readonly='read-only'></td>");
                   out.println("</tr>");
                   out.println("<tr>");
                   out.println("<td class='LABELRESULT'>Cédula:</td>");
                   out.println("<td class='CELDACAMPORESULT'><input type='text' name='txtCedula' value='" + strCedula + "' id='txtCedula' class='CAMPORESULT' readonly='read-only'></td>");
                   out.println("<td class='LABELRESULT'>Nombre del usuario:</td>");
                   out.println("<td class='CELDACAMPORESULT'><input type='text' name='txtNomUsuario' value='" + strNombre + "' id='txtNomUsuario' class='CAMPORESULT' readonly='read-only'></td>");
                   out.println("</tr>");
                   out.println("<tr>");
                   out.println("<td class='LABELRESULT'>Estado:</td>");
                   out.println("<td class='CELDACAMPORESULT'><input type='text' name='txtEstado' value='" + strEstado + "' id='txtEstado' class='CAMPORESULT' readonly='read-only'></td>");
                   out.println("<td class='LABELRESULT'>Fecha de entrega:<br>(aaaa-mm-dd)</td>");
                   out.println("<td class='CELDACAMPORESULT'><input type='text' name='txtFechaEntrega' value='" + strFechaEntrega+ "' id='txtFechaEntrega' class='CAMPORESULT' readonly='read-only'></td>");
                   out.println("</tr>");
                   out.println("<tr>");
                   out.println("<td class='LABELRESULT'>Descripción:</td>");
                   out.println("<td colspan='3' class='CELDACAMPORESULT'><input type='text' name='txtDescripcion' value='" + strDescripcion + "' id='txtDescripcion' class='CAMPORESULT' style='width: 860px;' readonly='read-only'></td>");
                   out.println("</tr>");
                   out.println("<tr>");
                   out.println("<td colspan='4'></td>");                    
                   out.println("</tr>");
                   out.println("</table>");
                   out.println("</form>");
                   out.println("</td>");
                   out.println("</tr>");
                   out.println("</table>"); 
                   out.println("</body>");
                   out.println("</html>");
               }else{
                   out.println("<html>");
                   out.println("<head>");
                   out.println("</head>");
                   out.println("<body>");
                   out.println("<div class='TEXTOFALLO'>");
                   out.println("No cuenta con la autorización para consultar la muestra con consecutivo " + strConsecutivo + ".");
                   out.println("</div>");
                   out.println("</body>");
                   out.println("</html>");
               }           
            }
        }finally{            
            out.close();
        }
    }    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
